using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.LoadTesting;
using FixCounterComputedValues;

namespace CounterReporting
{
    public class CounterFixupPlugin : ILoadTestPlugin
    {
        #region ILoadTestPlugin Members
        CounterFixup mFixup;
        int mCurrentRunId = -1;

        public void Initialize(LoadTest loadTest)
        {
            //Fix the database server.   One possibility is to set this in a load test context parameter
            //and read the value from the parameter.
            mFixup = new CounterFixup(".\\SQLEXPRESS");
            loadTest.LoadTestStarting += new EventHandler(loadTest_LoadTestStarting);
            loadTest.LoadTestFinished += new EventHandler(loadTest_LoadTestFinished);
            
        }

        void loadTest_LoadTestFinished(object sender, EventArgs e)
        {

            mFixup.FixAllInstanceSamples(mCurrentRunId);
        }

        void loadTest_LoadTestStarting(object sender, EventArgs e)
        {
            mCurrentRunId = mFixup.GetMaxLoadTestRunId();
        }

        #endregion
    }
}
